
#include <iostream>
#include <assert.h>
#include <stdio.h>
#include <vector>
#include <boost/filesystem/operations.hpp>
#include "../org/vars.h"
#include "../org/audioinfo.h"
#include "../org/rule.h"
#include "../org/ruleio.h"
#include "../org/ruleinterpreter.h"
#include "../fileoperations.h"

#ifndef TEST_ORGANISER_RULES_PATH
#define TEST_ORGANISER_RULES_PATH "test_xml/test_organiser_rules.xml"
#endif

using namespace boost;
namespace bf = boost::filesystem;
using namespace Org;


void test_organiser_run_rules()
{

}

void test_ruleinterpreter_rule_complies_xml()
{

    cout << "\ntest_ruleinterpreter_rule_complies_xml()...";

    Org::RuleIO rule_reader;    
    vector<Rule> rules = rule_reader.read_xml(TEST_ORGANISER_RULES_PATH);


    Rule first_rule = rules[0];
    Rule sec_rule = rules[1];


    cout << "rulename=" << first_rule.rule_name << endl;


    // complies with first rule
    /*bf::path path_complies = "test_dir/Test_rule_complies/Braintax_id3_right";
    assert(RuleInterpreter::rule_complies(first_rule, path_complies));

    // does not comply with first rule
    bf::path path_not_complies = "test_dir/Test_rule_complies/Braintax_id3_wrong";
    assert(!(RuleInterpreter::rule_complies(first_rule, path_not_complies)));

    cout << "[passed]" << endl;
    */

}

void test_ruleinterpreter_rule_complies()
{
    cout << "\ntest_ruleinterpreter_rule_complies()... NOT IMPLEMENTED";

    // create rule that says if ((GENRE=="Hardcore" OR GENRE="Jungle OR GENRE="Dnb") && (YEAR==1991 OR YEAR==1992)) match
    Rule temp_rule("test rule");
    temp_rule.root_node = new Node();
    vector<Node> nodeAndList;

    // create AND join
    Node nodeAnd;
    nodeAnd.node_type = Vars::ORG_NODE_BOOL;
    nodeAnd.operation = Vars::ORG_AND;
    nodeAndList.push_back(nodeAnd);

    // create first OR condition set
    Node nodeHardcore;
    nodeHardcore.node_type = Vars::ORG_NODE_CONDITION;
    nodeHardcore.search_type = Vars::ORG_ID3;
    nodeHardcore.search_in = "GENRE";

    Node nodeJungle;
    nodeJungle.node_type = Vars::ORG_NODE_CONDITION;
    nodeJungle.search_type = Vars::ORG_ID3;
    nodeJungle.search_in = "GENRE";

    Node nodeDnb;
    nodeDnb.node_type = Vars::ORG_NODE_CONDITION;
    nodeDnb.search_type = Vars::ORG_ID3;
    nodeDnb.search_in = "GENRE";

    // create second OR condition set
    Node nodeYear1;
    nodeYear1.node_type = Vars::ORG_NODE_CONDITION;
    nodeYear1.search_type = Vars::ORG_ID3;
    nodeYear1.search_in = "YEAR";

    Node nodeYear2;
    nodeYear2.node_type = Vars::ORG_NODE_CONDITION;
    nodeYear2.search_type = Vars::ORG_ID3;
    nodeYear2.search_in = "YEAR";


    Org::AudioInfo audio_info_matches("test_files/test_id3.mp3");
    Org::AudioInfo audio_info_not_matches("test_files/test_id3.mp3");
    cout << "[passed]" << endl;
}



void run_testsuite_lu()
{
    test_ruleinterpreter_rule_complies_xml();
    test_organiser_run_rules();
    cout << ".. running Organiser and Rule Interpreter tests" << endl;
}


